import axios from "axios";
import router from "../router";
const api = axios.create({
  // timeout: 30000,
  baseURL: "",
});

// 请求拦截器
api.interceptors.request.use(
  config => {
    let Token = localStorage.getItem("Token");
    if (Token) config.headers.common["Authorization"] = "Bearer " + Token;
    return config;
  },
  err => {
    throw err;
  },
);

//响应拦截器
api.interceptors.response.use(
  config => {
    if (config.data.Code == 401) {
      router.push({ name: "Login" });
      localStorage.clear();
    }
    return config;
  },
  err => {
    throw err;
  },
);

export default api;
